<template>
  <div id="BondsMaintain">
    <div class="query">
      <!-- --------------- -->
      <div class="homeTitle admin">
        <span>债券资料维护</span>
        <el-input placeholder="搜索债券代码" v-model="code" class="input-with-select">
          <el-button slot="append" icon="el-icon-search" @click="getdata(1)"></el-button>
        </el-input>
      </div>
      <div class="queryCon">
        <div class="qSeles">
          <!-- 两个选择 -->
          <div class="xuanze">
            <div class="xuanzeCon">
              <span>债券性质：</span>
              <el-select v-model="nature" placeholder="请选择" size="small">
                <el-option
                  v-for="item in xzoptions"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </div>
            <div class="xuanzeCon">
              <span>主体评级：</span>
              <el-select v-model="subject" placeholder="请选择" size="small">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </div>
            <div class="xuanzeCon">
              <span>债项评级：</span>
              <el-select v-model="debt" placeholder="请选择" size="small">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </div>
          </div>
          <!-- 按钮 -->
          <div class="btnAb">
            <el-button type="primary" size="small" @click="getdata(1)">查询</el-button>
            <el-button type="primary" size="small" @click="xinzeng">新增债券资料</el-button>
          </div>
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <div class="table">
      <!-- 表格 -->
      <div class="tablecon">
        <el-table :data="tableData" border style="width: 100%">
           <el-table-column prop="code" label="债券代码" align="center"></el-table-column>
          <el-table-column prop="name" label="债券全称" align="center"></el-table-column>
          <el-table-column prop="simple" label="债券简称" align="center"></el-table-column>
          <el-table-column prop="nature" label="债券性质" align="center"></el-table-column>
          <el-table-column prop="mainUnderwrite" label="主承销商" align="center"></el-table-column>
          <el-table-column prop="mechanismName" label="发行机构名称" align="center"></el-table-column>
          <el-table-column prop="subject" label="主体评级" align="center"></el-table-column>
          <el-table-column prop="debt" label="债项评级" align="center"></el-table-column>
          <el-table-column prop="address" label="操作" align="center" width="172">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="lookDetail(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
       <!-- 分页 -->
      <div class="pgfy">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="10"
          layout="total, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "BondsMaintain",
  data() {
    return {
      options: [
          {label: '全部', value: ''},{label: 'AAA', value: 'AAA'},
          {label: 'AA+', value: 'AA+'},{label: 'AA', value: 'AA'},
          {label: 'AA-', value: 'AA-'},{label: 'A+', value: 'A+'},
          {label: 'A', value: 'A'},{label: 'A-', value: 'A-'},
          {label: 'BBB+', value: 'BBB+'},{label: 'BBB', value: 'BBB'},
          {label: 'BB+', value: 'BB+'},{label: 'BB', value: 'BB'},
          {label: 'BB-', value: 'BB-'},{label: 'B+', value: 'B+'},
          {label: 'B', value: 'B'},{label: 'B-', value: 'B-'},
          {label: 'CCC+', value: 'CCC+'},{label: 'CCC', value: 'CCC'},
          {label: 'CC+', value: 'CC+'},{label: 'CC', value: 'CC'},
          {label: 'CC-', value: 'CC-'},{label: 'C+', value: 'C+'},
          {label: 'C', value: 'C'},{label: 'C-', value: 'C-'},
      ],
      xzoptions: ['全部','国债','地方政府债','央行票据','政策性银行债券','政策性银行次级债','商业银行债券','商业银行次级债','中期票据','企业债','短期融资券','其他金融债','集合票据','资产支持证券','其他债券','公司债','二级资本工具','非公开定向债务融资工具','同业存单','资产管理公司金融债','超短期融资券','铁道债','可分离债'],
      value: "",
      code: "",
      nature: "全部",//债券性质
      subject: "",//主体评级
      debt: "",//债项评级
      tableData: [],
      // 分页
      currentPage: 1,
      total: null,
      obj: ''
    };
  },
  methods: {
    getdata(val) {
      this.currentPage = val;
      let obj= {
        code: this.code,
        nature: this.nature,
        subject: this.subject,
        debt: this.debt,
        page: this.currentPage
      }
      this.obj = obj;
      this.axios.get('bond/selectList',{params:this.filterNoneObj(obj)})
        .then(({data}) => {
          if (data.code == 200) {
            this.tableData = data.data;
            this.total = data.pageInfo.total;
          }
        })
    },
    paramsGetdata (val) {
      let obj =  JSON.parse(sessionStorage.getItem('BondsMaintainParams'));
      this.obj = obj;
      this.code = obj.code;
      this.nature = obj.nature;
      this.subject = obj.subject;
      this.debt = obj.debt;
      this.currentPage = obj.page;
      this.axios.get('bond/selectList',{params:this.filterNoneObj(obj)})
        .then(({data}) => {
          if (data.code == 200) {
            this.tableData = data.data;
            this.total = data.pageInfo.total;
          }
        })
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getdata(val);
    },
    lookDetail(row) {
      sessionStorage.setItem('BondsMaintainParams', JSON.stringify(this.obj));
      this.$router.push({path: "modifyBondDetails", query:{id: row.id}});
    },
    xinzeng() {
      this.$router.push("bondDetails");
    },
  },
  beforeRouteEnter(to, from, next){
    next(vm=>{
      if(from.path=='/modifyBondDetails' && sessionStorage.BondsMaintainParams) {
        vm.paramsGetdata();
      } else {
        vm.getdata(1);
      }
    })
  }
};
</script>

<style lang="scss">
#BondsMaintain {
  .homeTitle {
    &.admin {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 20px;
      border-bottom: 1px solid black;
      .el-input {
        width: 300px;
      }
    }
  }
  .queryCon {
    background: white;
    padding: 0 20px 20px;
    .qSeles {
      padding-top: 20px;
      .xuanze {
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        flex-wrap: wrap;
        .xuanzeCon {
          height: 40px;
          display: flex;
          align-items: center;
          margin-right: 30px;
          .el-input {
            width: 200px;
          }
        }
      }
      .btnAb {
        margin-top: 30px;
        .el-button {
          margin-right: 30px;
        }
      }
    }
  }
  .table {
    background: white;
    .tablecon {
      padding: 20px;
    }
    .pgfy {
      padding: 20px;
      padding-top: 10px;
      text-align: right;
    }
  }
}
</style>
